<template>
	<view>
		<view class="card" @click="showLine(item.subjectId)" v-for="(item,index) in titleData" :key="index">
			<view :class="item.subjectId == showLineId?'line-box':''">
				<view class="title">
					<span v-if="item.isMustAnswer">*</span><text>{{index+1}}.{{item.title}}</text>
				</view>
				<view class="content">
					<!-- 填空题 -->
					<view class="fill" v-if="item.questionType==3">
						<view class="inputBox" :class="item.multilineText==1?'multipleLines':''">
						</view>
					</view>
					<!-- 单选题 -->
					<view class="single" v-else-if="item.questionType == 1">
						<!-- 分组 -->
						<view class="grouping" v-if="item.isGroup">
							<template v-if="item.numberOfOptions !== '下拉菜单'">
								<block v-for="group in item.groupingArray" :key="group.id">
									<text class="groupTitle">{{group.content}}</text>
									<!-- 每行两列 -->
									<view v-if="item.numberOfOptions == '2'">
										<block v-for="(option,optionIndex) in group.optionData" :key="optionIndex">
											<block v-if="(optionIndex+1)%2==0">
												<label class="radio">
													<radio disabled style="transform:scale(0.6)" /><text>{{option}}</text>
												</label><br />
											</block>
											<block v-else>
												<label class="radio">
													<radio disabled style="transform:scale(0.6)" /><text>{{option}}</text>
												</label>
											</block>
										</block>
									</view>
									<!-- 横向排列 -->
									<view v-else-if="item.numberOfOptions == '横向排列'">
										<label class="radio" v-for="option in group.optionData" :key="option">
											<radio disabled style="transform:scale(0.6)" /><text>{{option}}</text>
										</label>
									</view>
									<!-- 每行一列，竖向排列 -->
									<view v-else>
										<p class="radio" v-for="option in group.optionData" :key="option">
											<radio disabled style="transform:scale(0.6)" /><text>{{option}}</text>
										</p>
									</view>
								</block>
							</template>
							<!-- 下拉菜单 -->
							<view v-else style="width: 90%;">
								<uni-data-select :disabled="true"></uni-data-select>
							</view>
						</view>
						<!-- 不分组 -->
						<view class="noGroup" v-else>
							<view v-if="item.numberOfOptions == '2'">
								<block v-for="(option,optionIndex) in item.optionArray" :key="optionIndex">
									<block v-if="(optionIndex+1)%2==0">
										<label class="radio">
											<radio disabled style="transform:scale(0.6)" /><text>{{option.content}}</text>
										</label><br />
									</block>
									<block v-else>
										<label class="radio">
											<radio disabled style="transform:scale(0.6)" /><text>{{option.content}}</text>
										</label>
									</block>
								</block>
							</view>
							<view v-else-if="item.numberOfOptions == '下拉菜单'">
								<view style="width: 90%;">
									<uni-data-select :disabled="true"></uni-data-select>
								</view>
							</view>
							<view v-else-if="item.numberOfOptions == '横向排列'">
								<block v-for="(option,optionIndex) in item.optionArray" :key="optionIndex">
									<label class="radio">
										<radio disabled style="transform:scale(0.6)" /><text>{{option.content}}</text>
									</label>
								</block>
							</view>
							<view v-else>
								<block v-for="(option,optionIndex) in item.optionArray" :key="optionIndex">
									<p class="radio">
										<radio disabled style="transform:scale(0.6)" /><text>{{option.content}}</text>
									</p>
								</block>
							</view>
						</view>
					</view>
					<!-- 多选题 -->
					<view class="multi" v-else-if="item.questionType==2">
						<!-- 分组 -->
						<block v-if="item.isGroup">
							<view v-for="group in item.groupingArray" :key="group">
								<text class="groupTitle">{{group.content}}</text>
								<checkbox-group>
									<block v-if="item.numberOfOptions == '2'">
										<label v-for="(option,optionIndex) in group.optionData" :key="optionIndex">
											<block v-if="(optionIndex+1)%2 ==0 ">
												<checkbox class="checkbox" disabled />
												<text>{{option}}</text><br />
											</block>
											<block v-else>
												<checkbox class="checkbox" disabled />
												<text>{{option}}</text>
											</block>
										</label>
									</block>
									<block v-else-if="item.numberOfOptions == '横向排列'">
										<label v-for="option in group.optionData" :key="option">
											<checkbox class="checkbox" disabled />
											<text>{{option}}</text>
										</label>
									</block>
									<block v-else>
										<p v-for="option in group.optionData" :key="option">
											<checkbox class="checkbox" disabled />
											<text>{{option}}</text>
										</p>
									</block>
								</checkbox-group>
							</view>
						</block>
						<!-- 不分组 -->
						<block v-else>
							<view v-if="item.numberOfOptions == '2'">
								<label v-for="(option,optionIndex) in item.optionArray" :key="optionIndex">
									<block v-if="(optionIndex+1)%2 ==0 ">
										<checkbox class="checkbox" disabled />
										<text>{{option.content}}</text><br />
									</block>
									<block v-else>
										<checkbox class="checkbox" disabled />
										<text>{{option.content}}</text>
									</block>
								</label>
							</view>
							<view v-else-if="item.numberOfOptions == '横向排列'">
								<label v-for="option in item.optionArray" :key="option">
									<checkbox class="checkbox" disabled />
									<text>{{option.content}}</text>
								</label>
							</view>
							<view v-else>
								<p v-for="option in item.optionArray" :key="option">
									<checkbox class="checkbox" disabled />
									<text>{{option.content}}</text>
								</p>
							</view>
						</block>
					</view>
				</view>
				<view class="edit" v-show="item.subjectId == showLineId">
					<view class="Divider"></view>
					<view class="myicons" @click="editTitle(item.subjectId,item.questionType,item)">
						<uni-icons type="compose" color="#a8a8a8" size="26"></uni-icons>
						<p style="color: #a8a8a8;">编辑</p>
					</view>
					<view class="myicons" @click="delTitle(item.subjectId,index)">
						<uni-icons type="trash" color="#a8a8a8" size="26"></uni-icons>
						<p style="color: #a8a8a8;">删除</p>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showLineId: 0
			};
		},
		props: ["titleData", "formid"],
		methods: {
			showLine(id) {
				if (this.showLineId == id) {
					this.showLineId = ''
				} else {
					this.showLineId = id
				}
			},
			// 编辑题目
			editTitle(subjectId, type, item) {
				let data = JSON.stringify(item);
				if (type == 1) {
					uni.navigateTo({
						url: '/components/addTitle/singleTopicSelection?formid=' + this.formid + '&subjectId=' + subjectId + '&item=' + data
					})
				}
				else if (type == 2) {
					uni.navigateTo({
						url: '/components/addTitle/multipleChoice?formid=' + this.formid + '&subjectId=' + subjectId + '&item=' + data
					})
				}
				else {
					uni.navigateTo({
						url: '/components/addTitle/fillsUpTheTopic?formid=' + this.formid + '&subjectId=' + subjectId + '&item=' + data
					})
				}
			},
			// 删除题目
			delTitle(subjectId, index) {
				this.$parent.del(subjectId, index)
			}
		}
	}
</script>

<style lang="less" scoped>
	.title {
		padding: 17px 12px 10px 12px;

		text {
			margin-left: 20rpx;
		}

		font-size: 35rpx;
		font-weight: bold;
	}

	.line-box {
		border: 1.2px dashed #7baa17;
	}

	.Divider {
		border-top: 1px solid #ccc;
	}

	.radio {
		/* margin-left: 20rpx; */
		margin-top: 10rpx;
	}

	.checkbox {
		margin-left: 20rpx;
		transform: scale(0.7)
	}

	.card {
		margin-top: 30rpx;
		background-color: white;

		span {
			color: red;
			position: absolute;
		}

		.content {
			.fill {
				display: flex;
				flex-direction: column;
				padding-bottom: 20px;

				.inputBox {
					width: 80%;
					height: 80rpx;
					border: 1px solid #e3e3e3;
					align-self: center;
				}

				.multipleLines {
					height: 140rpx;
				}
			}

			.single,
			.multi {
				margin-left: 70rpx;
				font-size: 30rpx;

				.grouping {
					.groupTitle {
						font-weight: bold;
					}
				}
			}
		}

		.edit {
			background-color: #ebebeb;

			.myicons {
				display: inline-block;
				margin-left: 25%;
				align-items: center;
			}
		}
	}

	/* 换行 */
	.aNewline {
		/* width: 50%; */
	}
</style>